/**
 * 获取市场情况
 * @param ctx
 * @returns {Promise<void>}
 */
exports.getStockMarketQuestion = async function (ctx) {
  try {
    const res = await ctx.services.stockConfig.getStockMarketQuestion()
    ctx.body = ctx.resuccess(res)
  } catch (err) {
    ctx.body = ctx.refail(err)
  }
}

/**
 * 更新市场情况
 * @param ctx
 * @returns {Promise<void>}
 */
exports.updateStockMarketQuestion = async function (ctx) {
  const query = ctx.request.body
  try {
    const data = ctx.validateData({
      key: { required: true, type: 'string' },
      value: { required: true, type: 'string' }
    }, query)
    await ctx.services.stockConfig.updateStockMarketQuestion(data)
    ctx.body = ctx.resuccess()
  } catch (err) {
    ctx.body = ctx.refail(err)
  }
}

/**
 * 更新仓位信息
 * @param ctx
 * @returns {Promise<void>}
 */
exports.updatePositionConfig = async function (ctx) {
  const query = ctx.request.body
  try {
    const data = ctx.validateData({
      position: { required: true, type: 'number' }
    }, query)
    await ctx.services.stockConfig.updatePositionConfig(data)
    ctx.body = ctx.resuccess()
  } catch (err) {
    ctx.body = ctx.refail(err)
  }
}

/**
 * 查询仓位信息
 * @param ctx
 * @returns {Promise<void>}
 */
exports.getPositionConfig = async function (ctx) {
  try {
    const res = await ctx.services.stockConfig.getPositionConfig()
    ctx.body = ctx.resuccess(res)
  } catch (err) {
    ctx.body = ctx.refail(err)
  }
}
